package com.kjlink.internal.report4vue.system.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.xuqiudong.common.base.model.BaseResponse;
import com.kjlink.internal.report4vue.base.controller.BaseApiController;
import com.kjlink.internal.report4vue.system.request.UserLoginRequest;
import com.kjlink.internal.report4vue.system.response.ApiLoginResponse;
import com.kjlink.internal.report4vue.system.response.ApiUserInfoResponse;
import com.kjlink.internal.report4vue.system.service.ApiSystemService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 描述:
 *
 * @author Vic.xu
 * @since 2024-11-22 16:30
 */
@RestController
public class ApiSystemController extends BaseApiController {


    @Resource
    private ApiSystemService apiSystemService;


    /**
     * 登录并返回 Token
     */
    @GetMapping(value = "/users/login")
    public BaseResponse<String> login() {
        return BaseResponse.success("get method do nothing!");
    }

    /**
     * 登录并返回 Token
     */
    @PostMapping(value = "/users/login")
    public BaseResponse<ApiLoginResponse> login(@RequestBody UserLoginRequest request) {
        return apiSystemService.login(request, response);
    }

    /**
     * 获取用户详情
     */
    @GetMapping("/users/info")
    public BaseResponse<ApiUserInfoResponse> info() {
        int userId = StpUtil.getLoginIdAsInt();
        return apiSystemService.userInfo(userId);
    }


}
